package de.uni.bremen.estudent.lbs.ui;


import android.app.Dialog;
import android.content.Context;
import android.text.Html;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;

import de.uni.bremen.estudent.lbs.R;
import de.uni.bremen.estudent.lbs.models.LbsOverlayItem;


public final class InformationDialog extends Dialog {

    public InformationDialog(final Context context, final LbsOverlayItem item) {
        super(context, R.style.FilterDialogTheme);
        this.setContentView(R.layout.overlay_dialog);
        this.setTitle(item.getTitle());
        this.setCancelable(true);
        this.setCanceledOnTouchOutside(true);

        TextView text = (TextView) this.findViewById(R.id.text);
        TextView contactView = (TextView) this
                                        .findViewById(R.id.contactInformation);

        text.setText(Html.fromHtml(item.getSnippet()));
        text.setMovementMethod(LinkMovementMethod.getInstance());

        String contact = item.getContactInformation();
        if (contact.equals("")) {
            contactView.setVisibility(View.GONE);
        } else {
            SpannableString contactWithLinks = new SpannableString(
                                            Html.fromHtml(contact));
            Linkify.addLinks(contactWithLinks, Linkify.ALL);

            contactView.setText(contactWithLinks);
            contactView.setMovementMethod(LinkMovementMethod.getInstance());
        }

        ScrollView sw = (ScrollView) this.findViewById(R.id.ScrollView);
        sw.setVisibility(View.VISIBLE);

        this.show();
    }

}
